package com.andon.microcellsimulator.common.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.andon.microcellsimulator.R;

/**
 * Created by Administrator on 2015/6/25.
 */
public class ZnkAlertDialog extends Dialog {

    public interface OnClickCallBack {
        void exec();
    }

    private Context mContent;

    private ZnkAlertDialog(Context context){
        super(context, R.style.znk_alert_dialog);
        mContent = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    public static ZnkAlertDialog createDialog(Context context, String message, final OnClickCallBack callBack){
        return createDialog(context, message, true, callBack);
    }

    public static ZnkAlertDialog createDialog(Context context, String message, final boolean closeable, final OnClickCallBack callBack){

        View view = LayoutInflater.from(context).inflate(R.layout.alert_dialog, null);
        RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.alert_view);
        TextView alertContent = (TextView) view.findViewById(R.id.alert_content);
        TextView alertBtn = (TextView) view.findViewById(R.id.alert_btn);

        final ZnkAlertDialog dialog = new ZnkAlertDialog(context);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(closeable);

        dialog.setContentView(layout, new RelativeLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        // 设置提示文字
        alertContent.setText(message);

        alertBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (closeable) {
                    dialog.dismiss();
                }

                if (callBack != null) {
                    callBack.exec();
                }
            }
        });

        return dialog;
    }
}
